<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Command-module for controlling TortoiseSVN from Windows Explorer &mdash; Dragonfly-modules v0.1 documentation</title>
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '0.1',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="top" title="Dragonfly-modules v0.1 documentation" href="index.html" />
    <link rel="next" title="Command-module for SharpReader feed aggregator" href="mod-sharpreader.html" />
    <link rel="prev" title="Command-module for Foxit Reader PDF viewer" href="mod-_foxitreader.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="mod-sharpreader.html" title="Command-module for SharpReader feed aggregator"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="mod-_foxitreader.html" title="Command-module for Foxit Reader PDF viewer"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">Dragonfly-modules v0.1 documentation</a> &raquo;</li> 
      </ul>
    </div>  
    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  
  <div class="section" id="command-module-for-controlling-tortoisesvn-from-windows-explorer">
<h1>Command-module for controlling <strong>TortoiseSVN</strong> from Windows Explorer<a class="headerlink" href="#command-module-for-controlling-tortoisesvn-from-windows-explorer" title="Permalink to this headline">¶</a></h1>
<p>This module implements various voice-commands for using the
Windows Explorer extensions of the TortoiseSVN subversion client.</p>
<ol class="loweralpha simple" start="3">
<li>Copyright 2008 by Daniel J. Rocco</li>
</ol>
<p>Licensed under the Creative Commons Attribution-
Noncommercial-Share Alike 3.0 United States License, see
&lt;<a class="reference external" href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">http://creativecommons.org/licenses/by-nc-sa/3.0/us/</a>&gt;</p>
<div class="section" id="configuration-examples">
<h2>Configuration examples<a class="headerlink" href="#configuration-examples" title="Permalink to this headline">¶</a></h2>
<div class="section" id="configuration-tortoisesvn-en-txt">
<h3>Configuration &#8220;_tortoisesvn-en.txt&#8221;<a class="headerlink" href="#configuration-tortoisesvn-en-txt" title="Permalink to this headline">¶</a></h3>
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27</pre></td><td class="code"><div class="highlight"><pre><span class="c">#</span>
                    <span class="c"># Dragonfly config for TortoiseSVN</span>
<span class="c">#</span>

<span class="c">#--- TortoiseSVN configuration ---------------------------------------------</span>

<span class="n">tortoisesvn</span><span class="o">.</span><span class="n">path</span>     <span class="o">=</span> <span class="s">&quot;C:</span><span class="se">\\</span><span class="s">Program Files</span><span class="se">\\</span><span class="s">TortoiseSVN</span><span class="se">\\</span><span class="s">bin</span><span class="se">\\</span><span class="s">TortoiseProc.exe&quot;</span>
<span class="n">tortoisesvn</span><span class="o">.</span><span class="n">command</span>  <span class="o">=</span> <span class="s">&quot;(tortoise | subversion) &lt;command&gt;&quot;</span>
<span class="n">tortoisesvn</span><span class="o">.</span><span class="n">global_command</span> <span class="o">=</span> <span class="s">&quot;(tortoise | subversion) &lt;command&gt; &lt;predef&gt;&quot;</span>
<span class="n">tortoisesvn</span><span class="o">.</span><span class="n">actions</span>  <span class="o">=</span> <span class="p">{</span>
                        <span class="s">&quot;add&quot;</span><span class="p">:</span>         <span class="s">&quot;add&quot;</span><span class="p">,</span>
                        <span class="s">&quot;checkout&quot;</span><span class="p">:</span>    <span class="s">&quot;checkout&quot;</span><span class="p">,</span>
                        <span class="s">&quot;commit&quot;</span><span class="p">:</span>      <span class="s">&quot;commit&quot;</span><span class="p">,</span>
                        <span class="s">&quot;revert&quot;</span><span class="p">:</span>      <span class="s">&quot;revert&quot;</span><span class="p">,</span>
                        <span class="s">&quot;merge&quot;</span><span class="p">:</span>       <span class="s">&quot;merge&quot;</span><span class="p">,</span>
                        <span class="s">&quot;delete&quot;</span><span class="p">:</span>      <span class="s">&quot;delete&quot;</span><span class="p">,</span>
                        <span class="s">&quot;diff&quot;</span><span class="p">:</span>        <span class="s">&quot;diff&quot;</span><span class="p">,</span>
                        <span class="s">&quot;log&quot;</span><span class="p">:</span>         <span class="s">&quot;log&quot;</span><span class="p">,</span>
                        <span class="s">&quot;import&quot;</span><span class="p">:</span>      <span class="s">&quot;import&quot;</span><span class="p">,</span>
                        <span class="s">&quot;update&quot;</span><span class="p">:</span>      <span class="s">&quot;update&quot;</span><span class="p">,</span>
                        <span class="s">&quot;revert&quot;</span><span class="p">:</span>      <span class="s">&quot;revert&quot;</span><span class="p">,</span>
                        <span class="s">&quot;ignore&quot;</span><span class="p">:</span>      <span class="s">&quot;ignore&quot;</span><span class="p">,</span>
                        <span class="s">&quot;rename&quot;</span><span class="p">:</span>      <span class="s">&quot;rename&quot;</span><span class="p">,</span>
                        <span class="s">&quot;properties&quot;</span><span class="p">:</span>  <span class="s">&quot;properties&quot;</span><span class="p">,</span>
                        <span class="s">&quot;repository&quot;</span><span class="p">:</span>  <span class="s">&quot;repobrowser&quot;</span><span class="p">,</span>
                        <span class="s">&quot;edit conflict&quot;</span><span class="p">:</span> <span class="s">&quot;conflicteditor&quot;</span><span class="p">,</span>
                       <span class="p">}</span>
</pre></div>
</td></tr></table></div>
</div>
</div>
<div class="section" id="module-source-code">
<h2>Module source code<a class="headerlink" href="#module-source-code" title="Permalink to this headline">¶</a></h2>
<p>The most current version of this module can be downloaded from the <a class="reference external" href="http://dragonfly-modules.googlecode.com/svn/trunk/command-modules/_tortoisesvn.py">repository here</a>.</p>
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><pre>  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189</pre></td><td class="code"><div class="highlight"><pre><span class="c"># coding=utf-8</span>
<span class="c">#</span>
<span class="c"># (c) Copyright 2008 by Daniel J. Rocco</span>
<span class="c"># Licensed under the Creative Commons Attribution-</span>
<span class="c">#  Noncommercial-Share Alike 3.0 United States License, see</span>
<span class="c">#  &lt;http://creativecommons.org/licenses/by-nc-sa/3.0/us/&gt;</span>
<span class="c">#</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Command-module for controlling **TortoiseSVN** from Windows Explorer</span>
<span class="sd">============================================================================</span>

<span class="sd">This module implements various voice-commands for using the</span>
<span class="sd">Windows Explorer extensions of the TortoiseSVN subversion client.</span>

<span class="sd">(c) Copyright 2008 by Daniel J. Rocco</span>

<span class="sd">Licensed under the Creative Commons Attribution-</span>
<span class="sd">Noncommercial-Share Alike 3.0 United States License, see</span>
<span class="sd">&lt;http://creativecommons.org/licenses/by-nc-sa/3.0/us/&gt;</span>

<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">os.path</span>
<span class="kn">import</span> <span class="nn">subprocess</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">win32gui</span>
<span class="kn">import</span> <span class="nn">urllib</span>
<span class="c">#from subprocess import Popen</span>

<span class="kn">from</span> <span class="nn">dragonfly</span> <span class="kn">import</span> <span class="p">(</span><span class="n">Grammar</span><span class="p">,</span> <span class="n">ConnectionGrammar</span><span class="p">,</span> <span class="n">AppContext</span><span class="p">,</span> <span class="n">CompoundRule</span><span class="p">,</span>
                       <span class="n">Choice</span><span class="p">,</span> <span class="n">Window</span><span class="p">,</span> <span class="n">Config</span><span class="p">,</span> <span class="n">Section</span><span class="p">,</span> <span class="n">Item</span><span class="p">)</span>


<span class="c">#---------------------------------------------------------------------------</span>
<span class="c"># Set up this module&#39;s configuration.</span>

<span class="n">config</span>                     <span class="o">=</span> <span class="n">Config</span><span class="p">(</span><span class="s">&quot;TortoiseSVN&quot;</span><span class="p">)</span>
<span class="n">config</span><span class="o">.</span><span class="n">tortoisesvn</span>         <span class="o">=</span> <span class="n">Section</span><span class="p">(</span><span class="s">&quot;TortoiseSVN configuration&quot;</span><span class="p">)</span>
<span class="n">config</span><span class="o">.</span><span class="n">tortoisesvn</span><span class="o">.</span><span class="n">path</span>    <span class="o">=</span> <span class="n">Item</span><span class="p">(</span><span class="s">r&#39;C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe&#39;</span><span class="p">)</span>
<span class="n">config</span><span class="o">.</span><span class="n">tortoisesvn</span><span class="o">.</span><span class="n">command</span> <span class="o">=</span> <span class="n">Item</span><span class="p">(</span><span class="s">&quot;(tortoise | subversion) &lt;command&gt;&quot;</span><span class="p">)</span>
<span class="n">config</span><span class="o">.</span><span class="n">tortoisesvn</span><span class="o">.</span><span class="n">global_command</span> <span class="o">=</span> <span class="n">Item</span><span class="p">(</span><span class="s">&quot;(tortoise | subversion) &lt;command&gt; &lt;predef&gt;&quot;</span><span class="p">)</span>
<span class="n">config</span><span class="o">.</span><span class="n">tortoisesvn</span><span class="o">.</span><span class="n">actions</span> <span class="o">=</span> <span class="n">Item</span><span class="p">({</span>
                                   <span class="s">&quot;add&quot;</span><span class="p">:</span>         <span class="s">&quot;add&quot;</span><span class="p">,</span>
                                   <span class="s">&quot;checkout&quot;</span><span class="p">:</span>    <span class="s">&quot;checkout&quot;</span><span class="p">,</span>
                                   <span class="s">&quot;commit&quot;</span><span class="p">:</span>      <span class="s">&quot;commit&quot;</span><span class="p">,</span>
                                   <span class="s">&quot;revert&quot;</span><span class="p">:</span>      <span class="s">&quot;revert&quot;</span><span class="p">,</span>
                                   <span class="s">&quot;merge&quot;</span><span class="p">:</span>       <span class="s">&quot;merge&quot;</span><span class="p">,</span>
                                   <span class="s">&quot;delete&quot;</span><span class="p">:</span>      <span class="s">&quot;delete&quot;</span><span class="p">,</span>
                                   <span class="s">&quot;diff&quot;</span><span class="p">:</span>        <span class="s">&quot;diff&quot;</span><span class="p">,</span>
                                   <span class="s">&quot;log&quot;</span><span class="p">:</span>         <span class="s">&quot;log&quot;</span><span class="p">,</span>
                                   <span class="s">&quot;import&quot;</span><span class="p">:</span>      <span class="s">&quot;import&quot;</span><span class="p">,</span>
                                   <span class="s">&quot;update&quot;</span><span class="p">:</span>      <span class="s">&quot;update&quot;</span><span class="p">,</span>
                                   <span class="s">&quot;revert&quot;</span><span class="p">:</span>      <span class="s">&quot;revert&quot;</span><span class="p">,</span>
                                   <span class="s">&quot;ignore&quot;</span><span class="p">:</span>      <span class="s">&quot;ignore&quot;</span><span class="p">,</span>
                                   <span class="s">&quot;rename&quot;</span><span class="p">:</span>      <span class="s">&quot;rename&quot;</span><span class="p">,</span>
                                   <span class="s">&quot;properties&quot;</span><span class="p">:</span>  <span class="s">&quot;properties&quot;</span><span class="p">,</span>
                                   <span class="s">&quot;repository&quot;</span><span class="p">:</span>  <span class="s">&quot;repobrowser&quot;</span><span class="p">,</span>
                                   <span class="s">&quot;edit conflict&quot;</span><span class="p">:</span> <span class="s">&quot;conflicteditor&quot;</span><span class="p">,</span>
                                  <span class="p">},</span>
                                 <span class="p">)</span>
<span class="n">config</span><span class="o">.</span><span class="n">tortoisesvn</span><span class="o">.</span><span class="n">predef</span>  <span class="o">=</span> <span class="n">Item</span><span class="p">({</span>
                                   <span class="s">&quot;dragonfly | dee fly&quot;</span><span class="p">:</span> <span class="s">r&quot;C:\data\projects\Dragonfly\work dragonfly&quot;</span><span class="p">,</span>
                                  <span class="p">},</span>
                                 <span class="p">)</span>
<span class="c">#config.generate_config_file()</span>
<span class="n">config</span><span class="o">.</span><span class="n">load</span><span class="p">()</span>


<span class="c">#---------------------------------------------------------------------------</span>
<span class="c"># Utility generator function for iterating over COM collections.</span>

<span class="k">def</span> <span class="nf">collection_iter</span><span class="p">(</span><span class="n">collection</span><span class="p">):</span>
    <span class="k">for</span> <span class="n">index</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="n">collection</span><span class="o">.</span><span class="n">Count</span><span class="p">):</span>
        <span class="k">yield</span> <span class="n">collection</span><span class="o">.</span><span class="n">Item</span><span class="p">(</span><span class="n">index</span><span class="p">)</span>


<span class="c">#---------------------------------------------------------------------------</span>
<span class="c"># This module&#39;s grammar for use within Windows Explorer.</span>

<span class="k">class</span> <span class="nc">ExplorerGrammar</span><span class="p">(</span><span class="n">ConnectionGrammar</span><span class="p">):</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">ConnectionGrammar</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span>
            <span class="bp">self</span><span class="p">,</span>
            <span class="n">name</span><span class="o">=</span><span class="s">&quot;Explorer subversion&quot;</span><span class="p">,</span>
            <span class="n">context</span><span class="o">=</span><span class="n">AppContext</span><span class="p">(</span><span class="n">executable</span><span class="o">=</span><span class="s">&quot;explorer&quot;</span><span class="p">),</span>
            <span class="n">app_name</span><span class="o">=</span><span class="s">&quot;Shell.Application&quot;</span>
           <span class="p">)</span>

    <span class="k">def</span> <span class="nf">get_active_explorer</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">handle</span> <span class="o">=</span> <span class="n">Window</span><span class="o">.</span><span class="n">get_foreground</span><span class="p">()</span><span class="o">.</span><span class="n">handle</span>
        <span class="k">for</span> <span class="n">window</span> <span class="ow">in</span> <span class="n">collection_iter</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">application</span><span class="o">.</span><span class="n">Windows</span><span class="p">()):</span>
            <span class="k">if</span> <span class="n">window</span><span class="o">.</span><span class="n">HWND</span> <span class="o">==</span> <span class="n">handle</span><span class="p">:</span>
                <span class="k">return</span> <span class="n">window</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_log</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s">&quot;</span><span class="si">%s</span><span class="s">: no active explorer.&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">None</span>

    <span class="k">def</span> <span class="nf">get_current_directory</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">window</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_active_explorer</span><span class="p">()</span>
        <span class="n">path</span> <span class="o">=</span> <span class="n">urllib</span><span class="o">.</span><span class="n">unquote</span><span class="p">(</span><span class="n">window</span><span class="o">.</span><span class="n">LocationURL</span><span class="p">[</span><span class="mf">8</span><span class="p">:])</span>
        <span class="k">if</span> <span class="n">path</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">&quot;file:///&quot;</span><span class="p">):</span>
            <span class="n">path</span> <span class="o">=</span> <span class="n">path</span><span class="p">[</span><span class="mf">8</span><span class="p">:]</span>
        <span class="k">return</span> <span class="n">path</span>

    <span class="k">def</span> <span class="nf">get_selected_paths</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">window</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_active_explorer</span><span class="p">()</span>
        <span class="n">items</span> <span class="o">=</span> <span class="n">window</span><span class="o">.</span><span class="n">Document</span><span class="o">.</span><span class="n">SelectedItems</span><span class="p">()</span>
        <span class="n">paths</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">collection_iter</span><span class="p">(</span><span class="n">items</span><span class="p">):</span>
            <span class="n">paths</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">Path</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">paths</span>

    <span class="k">def</span> <span class="nf">get_selected_filenames</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">paths</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_selected_paths</span><span class="p">()</span>
        <span class="k">return</span> <span class="p">[</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">basename</span><span class="p">(</span><span class="n">p</span><span class="p">)</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">paths</span><span class="p">]</span>


<span class="c">#---------------------------------------------------------------------------</span>
<span class="c"># Create the rule from which the other rules will be derived.</span>
<span class="c">#  This rule implements the method to execute TortoiseSVN.</span>

<span class="k">class</span> <span class="nc">TortoiseRule</span><span class="p">(</span><span class="n">CompoundRule</span><span class="p">):</span>

    <span class="k">def</span> <span class="nf">_execute_command</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">path_list</span><span class="p">,</span> <span class="n">command</span><span class="p">):</span>
        <span class="c"># Construct arguments and spawn TortoiseSVN.</span>
        <span class="n">path_arg</span> <span class="o">=</span> <span class="s">&#39;/path:&quot;</span><span class="si">%s</span><span class="s">&quot;&#39;</span> <span class="o">%</span> <span class="nb">str</span><span class="p">(</span><span class="s">&#39;*&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path_list</span><span class="p">))</span>
        <span class="n">command_arg</span> <span class="o">=</span> <span class="s">&quot;/command:&quot;</span> <span class="o">+</span> <span class="n">command</span>
        <span class="n">os</span><span class="o">.</span><span class="n">spawnv</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">P_NOWAIT</span><span class="p">,</span> <span class="n">config</span><span class="o">.</span><span class="n">tortoisesvn</span><span class="o">.</span><span class="n">path</span><span class="p">,</span>
                  <span class="p">[</span><span class="n">config</span><span class="o">.</span><span class="n">tortoisesvn</span><span class="o">.</span><span class="n">path</span><span class="p">,</span> <span class="n">command_arg</span><span class="p">,</span> <span class="n">path_arg</span><span class="p">])</span>

        <span class="c"># For some reason the subprocess module gives quote-related errors.</span>
        <span class="c">#Popen([tortoise_path, command_arg, path_arg])</span>


<span class="c">#---------------------------------------------------------------------------</span>
<span class="c"># Create the rule for controlling TortoiseSVN from Windows Explorer.</span>

<span class="k">class</span> <span class="nc">ExplorerCommandRule</span><span class="p">(</span><span class="n">TortoiseRule</span><span class="p">):</span>

    <span class="n">spec</span> <span class="o">=</span> <span class="n">config</span><span class="o">.</span><span class="n">tortoisesvn</span><span class="o">.</span><span class="n">command</span>
    <span class="n">extras</span> <span class="o">=</span> <span class="p">[</span>
              <span class="n">Choice</span><span class="p">(</span><span class="s">&quot;command&quot;</span><span class="p">,</span> <span class="n">config</span><span class="o">.</span><span class="n">tortoisesvn</span><span class="o">.</span><span class="n">actions</span><span class="p">),</span>
             <span class="p">]</span>

    <span class="k">def</span> <span class="nf">_process_recognition</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">node</span><span class="p">,</span> <span class="n">extras</span><span class="p">):</span>
        <span class="n">selection</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">grammar</span><span class="o">.</span><span class="n">get_selected_paths</span><span class="p">()</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">selection</span><span class="p">:</span>
            <span class="n">selection</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">grammar</span><span class="o">.</span><span class="n">get_current_directory</span><span class="p">()]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_execute_command</span><span class="p">(</span><span class="n">selection</span><span class="p">,</span> <span class="n">extras</span><span class="p">[</span><span class="s">&quot;command&quot;</span><span class="p">])</span>


<span class="c">#---------------------------------------------------------------------------</span>
<span class="c"># Create the rule for controlling TortoiseSVN from anywhere.</span>

<span class="k">class</span> <span class="nc">GlobalCommandRule</span><span class="p">(</span><span class="n">TortoiseRule</span><span class="p">):</span>

    <span class="n">spec</span> <span class="o">=</span> <span class="n">config</span><span class="o">.</span><span class="n">tortoisesvn</span><span class="o">.</span><span class="n">global_command</span>
    <span class="n">extras</span> <span class="o">=</span> <span class="p">[</span>
              <span class="n">Choice</span><span class="p">(</span><span class="s">&quot;command&quot;</span><span class="p">,</span> <span class="n">config</span><span class="o">.</span><span class="n">tortoisesvn</span><span class="o">.</span><span class="n">actions</span><span class="p">),</span>
              <span class="n">Choice</span><span class="p">(</span><span class="s">&quot;predef&quot;</span><span class="p">,</span>  <span class="n">config</span><span class="o">.</span><span class="n">tortoisesvn</span><span class="o">.</span><span class="n">predef</span><span class="p">),</span>
             <span class="p">]</span>

    <span class="k">def</span> <span class="nf">_process_recognition</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">node</span><span class="p">,</span> <span class="n">extras</span><span class="p">):</span>
        <span class="n">path_list</span> <span class="o">=</span> <span class="p">[</span><span class="n">extras</span><span class="p">[</span><span class="s">&quot;predef&quot;</span><span class="p">]]</span>
        <span class="n">command</span> <span class="o">=</span> <span class="n">extras</span><span class="p">[</span><span class="s">&quot;command&quot;</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_execute_command</span><span class="p">(</span><span class="n">path_list</span><span class="p">,</span> <span class="n">command</span><span class="p">)</span>


<span class="c">#---------------------------------------------------------------------------</span>
<span class="c"># Load the grammar instance and define how to unload it.</span>

<span class="n">explorer_grammar</span> <span class="o">=</span> <span class="n">ExplorerGrammar</span><span class="p">()</span>
<span class="n">explorer_grammar</span><span class="o">.</span><span class="n">add_rule</span><span class="p">(</span><span class="n">ExplorerCommandRule</span><span class="p">())</span>
<span class="n">global_grammar</span> <span class="o">=</span> <span class="n">Grammar</span><span class="p">(</span><span class="s">&quot;TortoiseSVN global&quot;</span><span class="p">)</span>
<span class="n">global_grammar</span><span class="o">.</span><span class="n">add_rule</span><span class="p">(</span><span class="n">GlobalCommandRule</span><span class="p">())</span>

<span class="n">explorer_grammar</span><span class="o">.</span><span class="n">load</span><span class="p">()</span>
<span class="n">global_grammar</span><span class="o">.</span><span class="n">load</span><span class="p">()</span>

<span class="c"># Unload function which will be called by natlink at unload time.</span>
<span class="k">def</span> <span class="nf">unload</span><span class="p">():</span>
    <span class="k">global</span> <span class="n">explorer_grammar</span><span class="p">,</span> <span class="n">global_grammar</span>
    <span class="k">if</span> <span class="n">explorer_grammar</span><span class="p">:</span>
        <span class="n">explorer_grammar</span><span class="o">.</span><span class="n">unload</span><span class="p">()</span>
        <span class="n">explorer_grammar</span> <span class="o">=</span> <span class="bp">None</span>
    <span class="k">if</span> <span class="n">global_grammar</span><span class="p">:</span>
        <span class="n">global_grammar</span><span class="o">.</span><span class="n">unload</span><span class="p">()</span>
        <span class="n">global_grammar</span> <span class="o">=</span> <span class="bp">None</span>
</pre></div>
</td></tr></table></div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">Command-module for controlling <strong>TortoiseSVN</strong> from Windows Explorer</a><ul>
<li><a class="reference external" href="#configuration-examples">Configuration examples</a><ul>
<li><a class="reference external" href="#configuration-tortoisesvn-en-txt">Configuration &#8220;_tortoisesvn-en.txt&#8221;</a></li>
</ul>
</li>
<li><a class="reference external" href="#module-source-code">Module source code</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="mod-_foxitreader.html" title="previous chapter">Command-module for <strong>Foxit Reader</strong> PDF viewer</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="mod-sharpreader.html" title="next chapter">Command-module for <strong>SharpReader</strong> feed aggregator</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="_sources/mod-_tortoisesvn.txt">Show Source</a></li>
            </ul>
          <h3>Quick search</h3>
            <form class="search" action="search.html" method="get">
              <input type="text" name="q" size="18" /> <input type="submit" value="Go" />
              <input type="hidden" name="check_keywords" value="yes" />
              <input type="hidden" name="area" value="default" />
            </form>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="mod-sharpreader.html" title="Command-module for SharpReader feed aggregator"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="mod-_foxitreader.html" title="Command-module for Foxit Reader PDF viewer"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">Dragonfly-modules v0.1 documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2008, Christo Butcher.
      Last updated on Apr 10, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.5.1.
    </div>
  </body>
</html>